package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.util.Date;

import com.ag.utils.DateUtils;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.Coupons;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

public class CouponsGsonAdapter implements JsonSerializer<Coupons> {

	@Override
	public JsonElement serialize(Coupons src, Type typeOfSrc,
			JsonSerializationContext context) {
		JsonObject json = new JsonObject();
		json.addProperty("id", src.getId());
		json.addProperty("name", src.getName());
		json.addProperty("status", src.getStatus());
		json.addProperty(
				"expiryDate",
				DateUtils.format(DateUtils.YYYY_MM_DD_HH_MM,
						new Date(src.getExpiryDate() * 1000)));
		json.addProperty("price", DBConfigUtils.paserMoney(src.getPrice()));
		json.addProperty(
				"source",
				src.getType().equals(StylistConstants.Coupons.Type.EXCHANGE) ? "兑换优惠码获得"
						: "分享奖励获得");
		return json;
	}

}
